package git.soulbgm.common;


import git.soulbgm.common.enums.DBTypeEnum;

/**
 * 数据库上下文持有人
 *
 * @author 贺瑞杰
 * @date 2020/08/28
 */
public class DataBaseContextHolder {

    private static final ThreadLocal<DBTypeEnum> CONTEXT_HOLDER = new ThreadLocal<>();

    public static void set(DBTypeEnum dbType) {
        CONTEXT_HOLDER.set(dbType);
    }

    public static DBTypeEnum get() {
        return CONTEXT_HOLDER.get();
    }

    public static void master() {
        set(DBTypeEnum.MASTER);
        //System.out.println("切换到master");
    }

    public static void slave() {
        set(DBTypeEnum.SLAVE1);
        //System.out.println("切换到slave1");
    }

    /**
     * 使用默认的数据源
     */
    public static void clear() {
        CONTEXT_HOLDER.remove();
    }

}
